/*
 * Copyright (C) 2015-2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#ifndef PLANET_WARS_2D_RT_CORE_MODEL_PLANET_ESSENTIAL_H
#define PLANET_WARS_2D_RT_CORE_MODEL_PLANET_ESSENTIAL_H


#include "PlanetWars2dRT-core/utils/position_2d_uint.h"
#include "PlanetWars2dRT-core/utils/size_2d_uint.h"
#include "PlanetWars2dRT-core/utils/observers.h"


#define PLANET_LEVEL_CHANGER_NULL NULL


EXTERN_C_BEGIN


struct planet_t
{
  position_2d_uint position;
  size_2d_uint size;
  
  unsigned int life_current, life_max;
  
  unsigned short producing_capacity;
  unsigned short nb_updates_to_produce;
  unsigned short nb_updates_before_next_production;
  bool produce_when_neutral;
  
  unsigned char player_index;
  
  unsigned char level_current, level_max;
  bool /* level changed */ (*level_changer)(struct planet_t* this_planet);
  
  observers_t observers;
};

typedef struct planet_t planet_t;


void
planet_init_first_time_only_default(planet_t* a_planet);

void
planet_destructor(planet_t* a_planet);

static inline
bool
planet_can_be_upgraded(const planet_t* p)
{
  return
    p->level_current < p->level_max &&
    p->level_changer != PLANET_LEVEL_CHANGER_NULL;
}


EXTERN_C_END


#endif
